package com.td.erhome.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.td.erhome.R;
import com.td.erhome.models.CouonBaen;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2017/4/18 0018.
 */

public class CouponListAdapter extends RecyclerView.Adapter<CouponListAdapter.HouseHolder> {

    public List<CouonBaen.BalanceListBean>  mCoupon_list;

    private Context mContext;

    public CouponListAdapter(List<CouonBaen.BalanceListBean> coupon_list, Context context) {
        mCoupon_list = coupon_list;
        mContext = context;
    }

    public void addData(List<CouonBaen.BalanceListBean> coupon_list) {
        mCoupon_list.addAll(coupon_list);
        notifyDataSetChanged();
    }

    public void clearData() {
        mCoupon_list.clear();
        notifyDataSetChanged();
    }

    @Override
    public HouseHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_coupon_list_item, null);
        HouseHolder cardHolder = new HouseHolder(inflate);
        return cardHolder;
    }

    @Override
    public void onBindViewHolder(HouseHolder holder, int position) {
        holder.mTvTime.setText((mCoupon_list.get(position).tran_time).replace(" ","\n"));
        holder.mTvNum.setText(mCoupon_list.get(position).tran_type==1?"+"+mCoupon_list.get(position).tran_amount+"元":"-"+mCoupon_list.get(position).tran_amount+"元");
        holder.mTvType.setText("场景\n"+mCoupon_list.get(position).tran_title);

    }

    @Override
    public int getItemCount() {
        return mCoupon_list.size();
    }

    public class HouseHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_time)
        TextView mTvTime;
        @Bind(R.id.tv_num)
        TextView mTvNum;
        @Bind(R.id.tv_type)
        TextView mTvType;

        public HouseHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }

}
